﻿# -*- coding: utf-8 -*-

""" Работа с протоколом. Соединение, отправка/получение сообщений """

import xmpp

from logger import Logger

class Protocol(object):

    def __init__(self):
        self.client = None
        self.server = None
        self.port = None
        self.jid = None
        self.password = None

    def connect(self, jid, password, server = None, port = 5222):
        self.jid = xmpp.protocol.JID(jid)
        self.password = password

        self.client = xmpp.Client(self.jid.getDomain(), debug=[])

        if not server:
            server = self.jid.getDomain()

        # TODO
        self.client.connect(server=(server, port))

        self.client.auth(jid.getNone(), password)

        self.client.sendInitPresence()

    def auth(self, login, password, resource = None):
        pass